﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using LeonardoNews.Data;
using LeonardoNews.Models;

namespace LeonardoNews.Server.Repositories
{
    public class ArticlesRepository : EfRepository<Article>
    {
        public ArticlesRepository()
            : base(new NewsContext())
        {
        }

        public override IQueryable<Article> GetAll()
        {
            return base.GetAll()
                       .Include(a => a.Comments)
                       .Include(a => a.Comments
                                      .Select(c => c.User))
                       .Include(a => a.Votes)
                       .Include(a => a.Votes
                                      .Select(v => v.User));
        }

        public override Article GetSingle(int id)
        {
            return base.DbSet
                .Include(a => a.Comments)
                       .Include(a => a.Comments
                                      .Select(c => c.User))
                       .Include(a => a.Votes)
                       .Include(a => a.Votes
                                      .Select(v => v.User)).FirstOrDefault(a => a.ID == id);
        }
    }
}